package com.study.mike.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.itextpdf.text.DocumentException;
import com.study.mike.common.annotation.NeedDecrypt;
import com.study.mike.model.dto.BookDTO;
import com.study.mike.model.dto.CreateOrderDTO;
import com.study.mike.model.dto.QrDTO;
import com.study.mike.model.entity.Book;
import com.baomidou.mybatisplus.extension.service.IService;
import com.study.mike.model.po.DeleteBookPO;
import com.study.mike.model.po.QueryBookPO;
import com.study.mike.model.po.SetBookStatusPO;
import com.study.mike.model.po.UpdateBookPO;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author KangHui
 * @since 2022-07-08
 */
public interface BookService extends IService<Book> {
    /**
     * 新增书籍
     *
     * @param book
     * @return
     */
    BookDTO addBook(Book book);

    /**
     * 编辑数书籍
     *
     * @param book
     * @return
     */
    BookDTO editBook(UpdateBookPO book);

    /**
     * 删除书籍
     *
     * @param bookPO
     * @return
     */
    Boolean deleteBook(DeleteBookPO bookPO);

    /**
     * 分页获取书籍信息
     *
     * @param bookPO
     * @return
     */
    Page<BookDTO> queryBook(QueryBookPO bookPO);

    /**
     * 设置书籍状态
     *
     * @param bookStatusPO
     * @return
     */
    Boolean setStatus(SetBookStatusPO bookStatusPO);

    /**
     * 导入书籍
     *
     * @return
     * @throws Exception
     */
    Boolean importBook() throws Exception;

    /**
     * 导出书籍
     *
     * @return
     * @throws IOException
     */
    Boolean exportBook() throws IOException;

    /**
     * 下载书籍信息pdf
     *
     * @return
     * @throws IOException
     * @throws DocumentException
     */
    @NeedDecrypt
    Boolean downloadBook() throws IOException, DocumentException;

    /**
     * 获取booklist
     *
     * @return
     */
    List<BookDTO> bookList();

    /**
     * 保存或者更新书籍
     *
     * @param book
     * @return
     */
    boolean saveOrUpdateBook(Book book);

    /**
     * 批量保存book
     *
     * @return
     */
    boolean saveBatchBook();

    /**
     * 同步数据到缓存
     *
     * @return
     */
    boolean synchronizationData();

    /**
     * 读取缓存信息
     *
     * @return
     * @throws JsonProcessingException
     */
    List<Book> redisBookInfo() throws JsonProcessingException;

    /**
     * 生成支付二维码
     *
     * @param createOrderDTO
     * @return
     * @throws JsonProcessingException
     */
    QrDTO createQr(CreateOrderDTO createOrderDTO) throws JsonProcessingException;

    /**
     * 获取ip归属地
     *
     * @param ip
     * @return
     */
    String getIpAddress(String ip);
}
